#include "DecoyHeadEastState.h"
#include "SniperAssasinateTanksState.h"
#include "PDController.h"
#include "CaptureFlagState.h"
#include "DecoyHeadNorthState.h"

DecoyHeadEastState::DecoyHeadEastState(void)
{
	target = new AttractiveField(Vector2(350, 100));
}


DecoyHeadEastState::~DecoyHeadEastState(void)
{
	delete target;
}

Command DecoyHeadEastState::GetCommand(MultiAgent* agent) {
	if (SniperAssasinateTanksState::TargetsEliminated()) {
		agent->setState(new CaptureFlagState());
		return agent->GetCommand();
	}

	Vector2 tank_pos(agent->getTank()->pos[0], agent->getTank()->pos[1]);
	Vector2 trajectory = target->get_trajectory(tank_pos);

	// If we have gone far enough south, head back north
	if (trajectory.magnitude() < 50) {
		agent->setState(new DecoyHeadNorthState());
		return agent->GetCommand();
	}

	Command cmd = PDController::instance()->GetComand(agent->getTank(), trajectory);
	cmd.speed(1.0);
	return cmd;

}
